/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : HomeAction.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Nov 18, 2008       Raghu Sarraff			       Created
 */
package lwf.web.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwf.handler.IProcessHandler;
import lwf.web.struts.action.form.HomeActionForm;
import net.lwf.entity.UserPreferences;
import net.lwf.util.web.WebUtil;
import net.lwf.web.constant.IWebConstant;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


/**
 * Type the class description here
 *  
 */
public class HomeAction extends BaseAction {
	
	public ActionForward changegrade(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return home(mapping, form, request, response);
	} //home
	
	
	public ActionForward home(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

			//Removing to make sure breadcrumb and media information not displayed.
			WebUtil.removeAttribute(request, IWebConstant.OPERATION);
			WebUtil.removeAttribute(request, IWebConstant.SUBJECT);
			WebUtil.removeAttribute(request, IWebConstant.TOPIC);
			request.removeAttribute(IWebConstant.KNOWLEDGE_RESOURCES);
			WebUtil.removeAttribute(request, IWebConstant.TOPIC_MENU_INFO);
		return mapping.findForward("home");
	} //home
	
	public ActionForward showpref(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HomeActionForm haform = (HomeActionForm) form;
		UserPreferences preferences = haform.getPreferences();
		if (preferences == null) {
			preferences = getWebUser(request).getPreferences();
			if (preferences == null) {
				preferences = new UserPreferences();
			}
		}
		haform.setPreferences(preferences);
		
		return mapping.findForward("preferences");	
		
	} //showpref	
	
	public ActionForward save(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HomeActionForm haform = (HomeActionForm) form;
		UserPreferences preferences = haform.getPreferences();
		getWebUser(request).setPreferences(preferences);
				
		return home(mapping, form, request, response);		
	} //preferences	
	
	@Override
	public IProcessHandler getHandler(HttpServletRequest request) {
		return null;
	}

	@Override
	public String getPageTitle() {
		return null;
	}

	@Override
	public String getMainTitle() {
		return null;
	}

	@Override
	public String getPdfLink() {
		return null;
	}

	@Override
	public String getQuizLink() {
		return null;
	}
	
	

} //HomeAction

